<?php
namespace classlib\core\middleware;
class log extends middleware {
	//操作SQL日志的前缀
	const FTSEGS   = 'admin/';
	const LOGLV    = 2;
	static $filter = array('delete', 'save', 'remove');
	/**
	 * 要实现的业务代码资料信息记录
	 * @return void
	 */
	public function doservice() {
		$start = microtime(true);
		if ($this->next) {
			$this->next->doservice();
		}
		$loger = \classlib\logger::inst();
		$loger->write('Elapsed Time:'.(microtime(true)-$start), 0, 'elapsed');
		//只记录POST操作 且登录的账号且请求/admin的后台操作
		if (strncmp(\classlib\core\router::$uri, self::FTSEGS, strlen(self::FTSEGS)) == 0 
			&& isset($_SERVER['REQUEST_METHOD']) && strcmp($_SERVER['REQUEST_METHOD'], 'POST') == 0 
			&& \classlib\core\view\view_abstract::$debug) {
			foreach (self::$filter as $fstr) {//判断操作中是否含有以上关键词Delete/Remove/Save
				if (stripos(\classlib\core\router::$app['method'], $fstr) !== false) {
					$loger->write(\classlib\core\view\view_abstract::$debug, self::LOGLV);
					break;
				}
			}
		}
	}
}